package com.wlyuan.open.scanner.assembler;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.open.dto.OpenOrderSyncDTO;
import com.wlyuan.open.scanner.domain.order.Order;
import com.wlyuan.open.scanner.utils.mappings.MappingInvalid;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author lijing
 * @description
 */
public class ScannerOrderAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {MappingInvalid.class, MappingIds.class})
    public interface Assembler {

        /**
         * 转换
         *
         * @param source
         * @return
         */
        @Mappings({
                @Mapping(source = "info.signTime", target = "info.signAt"),
                @Mapping(source = "info.create", target = "info.createMan"),
                @Mapping(source = "info.createTime", target = "info.createOrderTime"),
                @Mapping(source = "info.updateTime", target = "info.updateTime"),
                @Mapping(source = "info.singer", target = "info.signBy"),
                @Mapping(source = "info.receiptTime", target = "info.receiptAt"),
                @Mapping(source = "info.totalAmount", target = "info.totalQuantity"),

                @Mapping(source = "info.signQuantity", target = "info.totalSignQuantity"),
                @Mapping(source = "info.signExceptionQuantity", target = "info.totalSignExceptionQuantity"),
                @Mapping(source = "info.receiptQuantity", target = "info.totalReceiptQuantity"),
                @Mapping(source = "info.receiptExceptionQuantity", target = "info.totalReceiptExceptionQuantity"),

        })
        OpenOrderSyncDTO assemble(Order source);

        /**
         * 转换
         *
         * @param source
         * @return
         */
        List<OpenOrderSyncDTO> assemble(List<Order> source);

    }

    public static List<OpenOrderSyncDTO> assemble(List<Order> creation) {
        return ASSEMBLER.assemble(creation);
    }

    public static OpenOrderSyncDTO assemble(Order creation) {
        return ASSEMBLER.assemble(creation);
    }

}
